package com.sskj.b70.v.activity;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.ImageView;

import com.sskj.b70.R;
import com.sskj.b70.common.App;
import com.sskj.b70.receiver.HomeBroadcastReceiver;
import com.sskj.b70.receiver.ScreenBroadcastReceiver;
import com.sskj.b70.utils.ImageUtil;
import com.sskj.b70.utils.RxSchedulersHelper;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Flowable;
import io.reactivex.functions.Consumer;

public class SplashActivity extends AppCompatActivity {

    @BindView(R.id.ll_image)
    ImageView llImage;
    private HomeBroadcastReceiver mHomeReceiver;
    private ScreenBroadcastReceiver mScreenReceiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mHomeReceiver == null) {
            mHomeReceiver = new HomeBroadcastReceiver();
            mHomeReceiver.registerScreenBroadcastReceiver(App.INSTANCE);
        }
        if (mHomeReceiver == null) {
            mScreenReceiver = new ScreenBroadcastReceiver();
            mHomeReceiver.registerScreenBroadcastReceiver(App.INSTANCE);
        }
        setNavigationBarColor();
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        ImageUtil.setImage(R.mipmap.splash, llImage);
        Flowable.timer(3, TimeUnit.SECONDS).compose(RxSchedulersHelper.transformer()).subscribe(new Consumer<Long>() {
            @Override
            public void accept(Long aLong) throws Exception {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }


    private void setNavigationBarColor() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            // Translucent navigation bar
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }
}
